AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

function ENT:Initialize()
	self:SetModel("models/props_c17/canister_propane01a.mdl")
	self:DrawShadow(false)

	self.Fuel = MEGABOOSTER_FUEL
end

function ENT:Think()
	if 0 < self:GetSkin() and 0 < self.Fuel then
		self.Fuel = self.Fuel - FrameTime()
		if self.Fuel <= 0 then
			self:CreateDebris()
			self:Remove()
		else
			local newskin = math.max(1, 100 - math.ceil((self.Fuel / MEGABOOSTER_FUEL) * 100))
			if self:GetSkin() ~= newskin then self:SetSkin(newskin) end

			local vehicle = self:GetOwner()
			if vehicle:IsValid() then
				vehicle:GetPhysicsObject():ApplyForceCenter(FrameTime() * MEGABOOSTER_FORCE * vehicle:GetForward())
			end
		end
	end

	self:NextThink(CurTime())
	return true
end

function ENT:KeyPress(pl, vehicle, key)
	if key == IN_ATTACK and vehicle.Powerups[1] == self and 0 == self:GetSkin() then
		self:SetSkin(1)
		self:EmitSound("Weapon_RPG.Single")
	end
end

function ENT:OnRemove()
	local vehicle = self:GetOwner()
	if vehicle:IsValid() then
		vehicle:RemovePowerup(self)
	end
end

function ENT:VehicleSet(eVehicle, bExists)
	--eVehicle:RemoveStatus("weapon_*", true, true, "status_weapon_megabooster")
	if not bExists then
		eVehicle:AddPowerup(self)
	end

	local ang = eVehicle:GetAngles()
	self:SetPos(eVehicle:GetPos() + (ang:Up() * 24 + ang:Forward() * -64) * SCALE)
	ang:RotateAroundAxis(ang:Right(), 90)
	self:SetAngles(ang)
end
